#include "../include/DirScanner.hpp"
#include <iostream>
#include <dirent.h>
#include <string.h>

using std::cout;
using std::endl;

namespace wd
{

DirScanner::DirScanner(const string &dir)
: _dir(dir)
{
    traverse();    
}

vector<string>& DirScanner::get_absolute_files()
{
    return _files;
}

void DirScanner::traverse()
{
    DIR *pdir;
    pdir = opendir(_dir.c_str());
    if(pdir == NULL){
        cout << __FILE__ << ":" << __FUNCTION__ << ":" << __LINE__ << " opendir ERROR!" << endl;
        return;
    }
    struct dirent* pdirent;
    while((pdirent = readdir(pdir)) != NULL){
        if(strcmp(pdirent->d_name, ".") == 0 || 
           strcmp(pdirent->d_name, "..") == 0){
            continue;
        }else{
            string file = _dir;
            file += '/';
            file += pdirent->d_name;
            _files.push_back(file);
        }
    }
    closedir(pdir);
    /* for(auto& elem : _files){ */
    /*     cout << elem << endl; */
    /* } */
    return;
}


}//end of namespace wd

